<?php

// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 流年 <liu21st@gmail.com>
// +----------------------------------------------------------------------
// 应用公共文件

/**
 * 将数据转换为 可供视图使用的分页数据
 * @param type $data
 * @param type $totleIndex
 * @param type $listIndex
 * @param type $low
 * @return type
 */
function dataToPagedata($data, $totleIndex = 'totle', $listIndex = 'list', $low = 10)
{
    $total         = $data[$totleIndex];
    $pageObj       = new \Org\util\Page($total, $low);
    $pageObj->setConfig('theme', '%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% %HEADER% ');
    $p_show        = $pageObj->show();
    $data['page']  = $p_show ? $p_show : '<span class="rows">共有' . $total . '条记录</span>';
    $data['total'] = $total;
    $data['list']  = $data[$listIndex];
    return $data;
}

/**
 * 查看所有的变量
 */
function allvar($yincang = false, $dump = false)
{
    $data = \think\View::instance()->get();
    if ($yincang) {
        unset($data['userinfo']);
        unset($data['menu_nav']);
    }
    if ($dump) {
        dump($data);
        return;
    }
    return $data;
}

function is_login()
{
    if (session('uid')) {
        return true;
    } else {
        return false;
    }
}
